/*global jQuery, $ */

// TODO: This code should be written in a closure
/**
 * Returns hash value from a href string
 * @param {String} href
 */
function getHash(href) {
	if (href.indexOf('#') > -1) {
		href = href.split('#')[1];
		href = href.split('?')[0];
	}
	
	return href;
}

/**
 * Helper for showing the correct page. Page is the the <div> witht he css class .page.
 * @param {String} href
 */
function goToPage(href) {
	var hash = getHash(href);
	
	if ($('#' + hash).length > 0) {
		$('.page').removeClass('show');
	
		$('#' + hash).addClass('show');	
		
		if (arguments.length > 1) {
			$('#' + hash).find('li:first a').attr('href', arguments[1]);
		}
	}
	
		
	
} 

// TODO: Move this to rateme.main.js
$(document).ready(function () {
	
	goToPage(window.location.href);

	$('.navigation a').click(function () {
		if (!$(this).hasClass('disabled')) {
			goToPage($(this).attr('href'));
		}
		
		return false;		
	});
});	